<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>menu</title>
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        .layui-btn:not(.layui-btn-lg):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div>
                <div class="layui-btn-group">
                    <button class="layui-btn layui-btn-normal" id="btn-refresh-publish-info">刷新选中设备信息</button>
                </div>
                <div class="layui-btn-group">
                    <button class="layui-btn layui-btn-normal" id="btn-start-select-account">启动所选账号</button>
                    <button class="layui-btn" id="btn-stop-select-account">停止所选账号</button>
                </div>
                <div class="layui-btn-group">
                    <button class="layui-btn" id="btn-expand">全部展开</button>
                    <button class="layui-btn" id="btn-fold">全部折叠</button>
                </div>
                <table id="munu-table" class="layui-table" lay-filter="munu-table"></table>
            </div>
        </div>
    </div>
    <!-- 操作列 -->
    <script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="startTask">开始任务</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="stopTask">停止任务</a>
</script>

    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script>
        layui.use(['table', 'treetable'], function () {
            var $ = layui.jquery;
            var table = layui.table;
            var treetable = layui.treetable;

            // 渲染表格
            layer.load(2);
            treetable.render({
                treeColIndex: 1,
                treeSpid: -1,
                treeIdName: 'authorityId',
                treePidName: 'parentId',
                elem: '#munu-table',
                url: '../api/menus.json',
                page: false,
                defaultToolbar: ['filter', 'exports', 'print'],
                cols: [[
                    { type: 'checkbox' }, // 添加勾选框列
                    // { type: 'numbers' },
                    { field: 'deviceName', width: 160, title: '设备名称' },
                    { field: 'accountNickName', width: 130, title: '昵称' },
                    { field: 'accountId', width: 130, title: '逛逛号' },
                    { field: 'orderAmountAndNum', width: 160, align: 'center', title: '种草成交金额/订单量', hide: true },
                    { field: 'commerceAmountAndNum', width: 160, align: 'center', title: '带货成交金额/订单量', hide: true },
                    { field: 'predictTotalAmount', width: 160, align: 'center', title: '预估总收入' },
                    { field: 'predictcommerceAmount', width: 160, align: 'center', title: '预估带货收入' },
                    { field: 'accountType', width: 100, align: 'center', title: '所属类目' },
                    { field: 'accountRemarks', width: 100, align: 'center', title: '备注' },
                    { field: 'accountStatus', width: 100, align: 'center', title: '状态' },
                    { templet: '#auth-state', minWidth: 120, align: 'center', title: '操作' }
                ]],
                done: function () {
                    layer.closeAll('loading');
                }
            });

            $('#btn-expand').click(function () {
                treetable.expandAll('#munu-table');
            });

            $('#btn-fold').click(function () {
                treetable.foldAll('#munu-table');
            });

            $('#btn-refresh-publish-info').click(function () {
                index = layer.load(0, { shade: false });
                delay(2000);
                layer.close(index);
                layer.msg('刷新选中设备信息成功');
            });

            $('#btn-set-publish-task').click(function () {
                let setPublishTaskPop = layer.open({
                    title: '批量设置发布任务',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: '../page/table/setPublishTask.html',
                });
            });

            $('#btn-set-publish-type').click(function () {
                let setDeviceTypePop = layer.open({
                    title: '批量设置类目',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['40%', '50%'],
                    content: '../page/table/setPublishType.html',
                })
            })

            $('#btn-set-publish-notes').click(function () {
                let setDeviceNotesPop = layer.open({
                    title: '批量备注',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['40%', '25%'],
                    content: '../page/table/setPublishNotes.html',
                })
            })

            function delay(ms) {
                return new Promise(resolve => setTimeout(resolve, ms));
            }

            //监听工具条
            table.on('tool(munu-table)', function (obj) {
                var data = obj.data;
                var layEvent = obj.event;

                if (layEvent === 'del') {
                    layer.msg('删除' + data.id);
                } else if (layEvent === 'edit') {
                    layer.msg('修改' + data.id);
                }
            });
        });
    </script>
</body>

</html>